<script type="text/javascript" src="/modules/menu/subnav.js"></script>
<script type="text/javascript">
var _subnav = new subnav();
</script>
<?php
//error_reporting(E_ALL);
//ini_set('display_errors','On');
if (!isset($_SESSION)) session_start();

//if(isset($_SESSION["username"])) include "{$_SERVER["DOCUMENT_ROOT"]}/modules/menu_edit/index.php";
global $navbar;


#include "data.php";
include "{$_SERVER["DOCUMENT_ROOT"]}/modules/menu/menu_json.php";
include "{$_SERVER["DOCUMENT_ROOT"]}/modules/menu/navbar_json.php";


//echo 1;
//print_r ($menu);



function navbar ($navsection) {
    global $navbar;
    global $menu;
    global $file;
    global $config;
    global $area;
    global $section;
   
    if ((isset($navbar[$navsection]))&&(count ($navbar[$navsection]) > 0)) {
        $items = "";
        $nav_id = 0;
        foreach ($navbar[$navsection] as $a) {
            if (is_array($a)) {
            //file_put_contents("{$_SERVER["DOCUMENT_ROOT"]}/logs/menu.txt", "items: '{$a}'\r\n",FILE_APPEND);
            $subnav = "";
            if ((isset($a["subnav"]))&&(count($a["subnav"])>0)) {						
        	foreach ($a["subnav"] as $sn) {
                    if ($sn["text"] != "")
                    $subnav .= "<li ";
                    if (basename($file) == basename($sn["url"]) || ($file == "" && $sn["url"] == "/")) $subnav .= " class=\"navbar_highlight\" ";
                    $subnav .= "><a href=\"{$sn["url"]}\"><span>{$sn["text"]}</span></a></li>";
        	}
        	$nav_id++;
        	$subnav = "<ul style=display:none id=subnav_$nav_id class=subnav>$subnav</ul>";
            }     	                          
            
            $items .= "<li";
            if ($subnav != "") $items .= " onclick=\"return _subnav.show('{$nav_id}')\" ";
            else $items .= " onclick=\"_subnav.clear();\" ";
                                                                
            if (basename($file) == basename($a["url"]) || ($file == "" && $a["url"] == "/")) $items .= " class=\"navbar_highlight\" ";
            if ($a["text"] != "") $items .= " ><a href=\"{$prefix}{$a["url"]}\"><span>{$a["text"]}</span></a></li>$subnav\n";
            }      
        }
        if($items != "") {
            echo <<<STOP
<div id=navmenu class="navmenu_holder r_7 {$config["layout"]["navmenu"]["row"]}"><ul>{$items}</ul></div>
STOP;
            return true;
        } else return false;
    } else return false;
}

echo <<<STOP

STOP;

$mainmenu="";
$submenu="";
$navmenu = "";
foreach ($menu as $key => $m) {
	if (!isset($menu[$key]["alt"])) {
    $op = $menu[$key]['text'];
    if (isset($menu[$key]["url"])) $op = "<a id=menu_{$key} href={$menu[$key]["url"]}>{$menu[$key]['text']}</a>";
    else $op = "<a id=menu_{$key} href=\"http://{$_SERVER['SERVER_NAME']}/{$key}\">{$menu[$key]['text']}</a>"; 
    $mainmenu .= "{$op}  ";
	}
	//$submenu .= $key;
	
    $key_id = $key;
	if (isset($menu[$key]["alt"]))  $key = $menu[$key]["alt"];
	//$submenu .= $key;
	//if (isset($menu[$key]["items"]))  $submenu .= "found"; 
    if (isset($menu[$key]["items"])) {
        //$op = "<a id=menu_{$key} href=\"http://{$_SERVER['SERVER_NAME']}/{$key}\">{$m['text']}</a>"; 
        $submenu .= "<div id={$key_id}_sub class=\"submenu  \" >";
        foreach ($menu[$key]["items"] as $s_key => $s) {
            
        	$submenu .= "<div style=float:left>";
        	$submenu .= "<div class=sub_menu_item>";
        	if (stripos($s["url"], "http://") === false) $sub_url = "http://{$_SERVER['SERVER_NAME']}/{$key}/{$s["section"]}/{$s["url"]}";
        	else $sub_url = $s["url"];
            $submenu .= "<a class=sub_menu_item id={$s["section"]} href=\"{$sub_url}\">{$s["text"]}</a> | ";
            
           
            $submenu .= "</div>";
            
             $submenu .= "<div ";
            if ($s["section"] == $key_id) $submenu .= " style=\"display:block;z-index:3;position:absolute;\" ";
            
            $submenu .= "  class=pointer><img ";
            if (strtolower($s["section"]) == "ucp") $submenu .= " style=\"margin-left:37px;\" ";
            $submenu .= "  src=\"/images/submenu_tri.png\"></div>";
        	$submenu .= "</div>";
                
            
        }
       
        $submenu .= "</div>\n";
    } ;
    //$mainmenu .= "{$op}  ";
}

if (! $config["nav_only"]) {
echo <<<STOP
<div id=menu_top class="menu_top upper r_2 w_15 h_0_75"><div id=menu_top_inner>{$mainmenu}</div></div>
<div id=submenu_holder class="submenu_holder r_2_75 w_14 h_0_5">{$submenu}</div>
STOP;
}



?>

<script type="text/javascript">

$("div.sub_menu_item").hover(function(){
	$(this).css("background-image","url('/images/prc_nav_grad.gif')");
	$(this).css("background-size","100px 18px");
	});

$("a.sub_menu_item").hover(function(){$(this).css("color","white");});

$("div.sub_menu_item").mouseleave(function(){$(this).css("background-image","");});

$("a.sub_menu_item").mouseleave(function() {
	if (!($(this).hasClass('h_item'))) $(this).css("color","#001751");
});
//alert(area)
</script>